<template>
  <div class="my_warp app_content">
    <!-- 导航栏 -->
    <!-- <div class="header_body">
      <header-nav :leftArrow="false" titelText="我的"></header-nav>
    </div> -->

    <div class="mine-top">
      <!-- <div class="title"></div> -->
      <div class="user">
        <div class="userImg">
          <img src="../assets/images/userImg.png" alt="" />
        </div>
        <div class="userInfo">
          <div class="name">{{ userInfo.userName }}</div>
          <div class="info" style="margin-bottom: 4px">
            {{ userInfo.deptName }}
          </div>
          <div class="info">{{ phoneStr }}</div>
        </div>
      </div>
    </div>

    <div class="mine-set" @click="setSign()">
      <div class="set-left">
        <img src="../assets/images/sginIcon.png" alt="" />
        <div>签名设置</div>
      </div>
      <div class="set-right">
        <img src="../assets/images/jiantou.png" alt="" />
      </div>
    </div>

    <div class="mine-set" @click="setPassword()">
      <div class="set-left">
        <img src="../assets/images/passwordIcon.png" alt="" />
        <div>修改密码</div>
      </div>
      <div class="set-right">
        <img src="../assets/images/jiantou.png" alt="" />
      </div>
    </div>

    <div class="mine-out">
      <van-button block type="primary" @click="outLogin" style="height: 47px" plain>
        退出登录
      </van-button>
    </div>

    <!-- 底部 -->
    <div class="footer_body">
      <footer-nav></footer-nav>
    </div>
  </div>
</template>

<script setup name="My">
import { showSuccessToast } from 'vant'
const { useLogin } = $globalStore
const router = useRouter()

const outLogin = async () => {
  const res = await useLogin.outLogin()
  if (res.code == 0) {
    sessionStorage.clear()
    showSuccessToast('退出成功')
    router.push({ name: 'App' })
  }
}

//获取用户信息
const userInfo = ref({})
const phoneStr = ref('')
const getUser = async () => {
  const res = await useLogin.getUserInfo()
  if (res.code == 0) {
    userInfo.value = res.data
    phoneStr.value =
      res.data.phone.toString().slice(0, 3).padEnd(7, '*') +
      res.data.phone.toString().slice(-4)
  }
}

const setSign = () => {
  router.push({
    name: 'setsign',
    query: {
      sign: userInfo.value.userSign,
    },
  })
}

const setPassword = () => {
  router.push({
    name: 'setpassword',
  })
}

onMounted(() => {
  getUser()
})
</script>
<style lang="less" scoped>
.app_content {
  height: calc(100% - 50px);
  overflow: auto;

  .mine-top {
    background: url('../assets/images/mineBg.png') no-repeat;
    background-size: 100% 100%;

    .title {
      padding: 10px 0;
      text-align: center;
      color: #ffffff;
      font-size: 17px;
      font-weight: 400;
    }

    .user {
      display: flex;
      align-items: center;
      padding: 42px 22px;

      .userImg {
        width: 80px;
        height: 80px;
        margin-right: 14px;

        >img {
          width: 80px;
          height: 80px;
        }
      }

      .userInfo {
        color: #ffffff;

        .name {
          font-size: 17px;
          font-weight: 700;
          line-height: 25px;
          margin-bottom: 4px;
        }

        .info {
          font-size: 14px;
          font-weight: 400;
          line-height: 21px;
        }
      }
    }
  }

  .mine-set {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid #f5f5f5;

    .set-left {
      display: flex;
      align-items: center;

      >img {
        width: 24px;
        height: 24px;
        margin-right: 8px;
      }

      >div {
        font-size: 17px;
        font-weight: 400;
        letter-spacing: 0px;
        line-height: 24px;
        color: #2b2b2b;
      }
    }

    .set-right {
      display: flex;
      align-items: center;

      >img {
        width: 12px;
        height: 20px;
      }
    }
  }

  .mine-out {
    margin-top: 40px;
    padding: 0 16px;
  }
}
</style>
